def is_prime(h):
    if h == 1:
        return False
    t = True
    j = h - 1
    while j > 1:
        if not h % j:
            t = False
            break
        j -= 1
    return t

k = input()
n = []
for i in range(len(k)):
    for q in range(i + 1, len(k) + 1):
        a = int(k[i:q])
        if is_prime(a):
            n += [a]
print(max(n) if n else 0)
